import '../model/follow_model.dart';

/// 用户关注默认数据
/// 提供默认的关注关系数据，使用默认用户ID
class FollowData {
  /// 获取所有默认关注数据
  static List<FollowModel> getDefaultFollows() {
    final now = DateTime.now();

    return [
      // 用户1 (admin) 关注其他用户
      FollowModel(
        id: '1',
        followerId: '1', // admin
        followingId: '2', // gardenmaster
        followTime: now.subtract(const Duration(days: 30)),
        isMutual: true,
      ),
      FollowModel(
        id: '2',
        followerId: '1', // admin
        followingId: '3', // leafyfriend
        followTime: now.subtract(const Duration(days: 25)),
        isMutual: true,
      ),
      FollowModel(
        id: '3',
        followerId: '1', // admin
        followingId: '4', // plantcare
        followTime: now.subtract(const Duration(days: 20)),
        isMutual: false,
      ),
      FollowModel(
        id: '4',
        followerId: '1', // admin
        followingId: '5', // greensoul
        followTime: now.subtract(const Duration(days: 15)),
        isMutual: true,
      ),

      // 用户2 (gardenmaster) 关注其他用户
      FollowModel(
        id: '5',
        followerId: '2', // gardenmaster
        followingId: '1', // admin
        followTime: now.subtract(const Duration(days: 28)),
        isMutual: true,
      ),
      FollowModel(
        id: '6',
        followerId: '2', // gardenmaster
        followingId: '3', // leafyfriend
        followTime: now.subtract(const Duration(days: 22)),
        isMutual: true,
      ),
      FollowModel(
        id: '7',
        followerId: '2', // gardenmaster
        followingId: '6', // blooming
        followTime: now.subtract(const Duration(days: 18)),
        isMutual: false,
      ),
      FollowModel(
        id: '8',
        followerId: '2', // gardenmaster
        followingId: '7', // plantlife
        followTime: now.subtract(const Duration(days: 12)),
        isMutual: true,
      ),

      // 用户3 (leafyfriend) 关注其他用户
      FollowModel(
        id: '9',
        followerId: '3', // leafyfriend
        followingId: '1', // admin
        followTime: now.subtract(const Duration(days: 23)),
        isMutual: true,
      ),
      FollowModel(
        id: '10',
        followerId: '3', // leafyfriend
        followingId: '2', // gardenmaster
        followTime: now.subtract(const Duration(days: 20)),
        isMutual: true,
      ),
      FollowModel(
        id: '11',
        followerId: '3', // leafyfriend
        followingId: '4', // plantcare
        followTime: now.subtract(const Duration(days: 16)),
        isMutual: false,
      ),
      FollowModel(
        id: '12',
        followerId: '3', // leafyfriend
        followingId: '8', // naturelover
        followTime: now.subtract(const Duration(days: 10)),
        isMutual: true,
      ),

      // 用户4 (plantcare) 关注其他用户
      FollowModel(
        id: '13',
        followerId: '4', // plantcare
        followingId: '1', // admin
        followTime: now.subtract(const Duration(days: 18)),
        isMutual: false,
      ),
      FollowModel(
        id: '14',
        followerId: '4', // plantcare
        followingId: '5', // greensoul
        followTime: now.subtract(const Duration(days: 14)),
        isMutual: true,
      ),
      FollowModel(
        id: '15',
        followerId: '4', // plantcare
        followingId: '6', // blooming
        followTime: now.subtract(const Duration(days: 8)),
        isMutual: false,
      ),

      // 用户5 (greensoul) 关注其他用户
      FollowModel(
        id: '16',
        followerId: '5', // greensoul
        followingId: '1', // admin
        followTime: now.subtract(const Duration(days: 13)),
        isMutual: true,
      ),
      FollowModel(
        id: '17',
        followerId: '5', // greensoul
        followingId: '4', // plantcare
        followTime: now.subtract(const Duration(days: 12)),
        isMutual: true,
      ),
      FollowModel(
        id: '18',
        followerId: '5', // greensoul
        followingId: '7', // plantlife
        followTime: now.subtract(const Duration(days: 6)),
        isMutual: false,
      ),

      // 用户6 (blooming) 关注其他用户
      FollowModel(
        id: '19',
        followerId: '6', // blooming
        followingId: '2', // gardenmaster
        followTime: now.subtract(const Duration(days: 16)),
        isMutual: false,
      ),
      FollowModel(
        id: '20',
        followerId: '6', // blooming
        followingId: '4', // plantcare
        followTime: now.subtract(const Duration(days: 6)),
        isMutual: false,
      ),
      FollowModel(
        id: '21',
        followerId: '6', // blooming
        followingId: '8', // naturelover
        followTime: now.subtract(const Duration(days: 4)),
        isMutual: true,
      ),

      // 用户7 (plantlife) 关注其他用户
      FollowModel(
        id: '22',
        followerId: '7', // plantlife
        followingId: '2', // gardenmaster
        followTime: now.subtract(const Duration(days: 10)),
        isMutual: true,
      ),
      FollowModel(
        id: '23',
        followerId: '7', // plantlife
        followingId: '5', // greensoul
        followTime: now.subtract(const Duration(days: 4)),
        isMutual: false,
      ),
      FollowModel(
        id: '24',
        followerId: '7', // plantlife
        followingId: '8', // naturelover
        followTime: now.subtract(const Duration(days: 2)),
        isMutual: true,
      ),

      // 用户8 (naturelover) 关注其他用户
      FollowModel(
        id: '25',
        followerId: '8', // naturelover
        followingId: '3', // leafyfriend
        followTime: now.subtract(const Duration(days: 8)),
        isMutual: true,
      ),
      FollowModel(
        id: '26',
        followerId: '8', // naturelover
        followingId: '6', // blooming
        followTime: now.subtract(const Duration(days: 2)),
        isMutual: true,
      ),
      FollowModel(
        id: '27',
        followerId: '8', // naturelover
        followingId: '7', // plantlife
        followTime: now.subtract(const Duration(days: 1)),
        isMutual: true,
      ),
    ];
  }

  /// 根据关注者ID获取关注列表
  static List<FollowModel> getFollowsByFollowerId(String followerId) {
    return getDefaultFollows()
        .where((follow) => follow.followerId == followerId)
        .toList();
  }

  /// 根据被关注者ID获取粉丝列表
  static List<FollowModel> getFollowsByFollowingId(String followingId) {
    return getDefaultFollows()
        .where((follow) => follow.followingId == followingId)
        .toList();
  }

  /// 根据用户ID获取互相关注列表
  static List<FollowModel> getMutualFollowsByUserId(String userId) {
    return getDefaultFollows()
        .where(
          (follow) =>
              (follow.followerId == userId || follow.followingId == userId) &&
              follow.isMutual,
        )
        .toList();
  }

  /// 检查两个用户是否互相关注
  static bool isMutualFollow(String userId1, String userId2) {
    final follows = getDefaultFollows();
    final follow1 = follows.any(
      (follow) => follow.followerId == userId1 && follow.followingId == userId2,
    );
    final follow2 = follows.any(
      (follow) => follow.followerId == userId2 && follow.followingId == userId1,
    );
    return follow1 && follow2;
  }
}
